package com.huage_08.lesson_04;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ReceiveDemo {
    public static void main(String[] args) throws IOException {
        //创建接收数据Socket对象
        DatagramSocket ds = new DatagramSocket(1997);

        //接收数据包
        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);//创建一个数据包准备接收数据
        ds.receive(dp);

        //解析数据包
        byte[] datas = dp.getData();
        String data = new String(datas,0,datas.length);

        System.out.println("接收到的数据为:" + data);

    }
}
